﻿window.$jscript.fn.wxlogin = (function () {
    var __FN = function () {
        return new __FN.fn._init();
    };
    var hxt = window.$jscript.fn;
    __FN.fn = __FN.prototype = {
        _init: function () { return this; },
        param: {
            key: '', link: '', components: {} },
        ready: function (options) {
            var self = this;
            $.each(options, function (idx, item) {
                if (self.param.hasOwnProperty(idx)) {
                    self.param[idx] = item;
                }
            });
            window.addEventListener('pageshow', function (e) {
                var a = e || window.event;
                if (a.persisted) {
                    window.location.reload()
                }
            });
            hxt.ready({ link: self.param.link, reqType: 2, key: self.param.key });
            self.initPage();
        },
       initPage: function () {
            var self = this;            
            hxt.element.elVue = new Vue({
                //router: router,
                data: function () {
                    var _this = this;
                    return {
                        account: '',
                        pwd: '',
                        userid: hxt.config.key,
                        bg: "",
                        phone: "",
                        password: ""
                    };
                },
                
                computed: {

                },
                mounted: function () {

                },
                methods: {
                    login: function () {
                        var _this = this;
                        if (!_this.account || _this.account.length < 2) return hxt.error(!_this.account ? '请输入账号' : '账号不正确');
                        if (!_this.pwd || _this.pwd.length < 4) return hxt.error(!_this.pwd ? '请输入密码' : '密码不正确');
                        hxt.post({
                            url: hxt.config.link + 'wx/wxLogin',
                            data: { account: _this.account, pwd: _this.pwd, wx_openId:_this.userid},
                            ok: function (res) {
                                if (res.code != 0) return hxt.error('登录失败：'+res.errmsg);
                                var url = 'go?state=userinfo&userid='+_this.userid;
                                window.open(url);
                            }
                        });
                    }
                },
                components: {
                    pcTurtle: function() { return hxt.staticComponent(self.param.components.wxPage, true); },
                }
            }).$mount('#wxlogin');
        }
    };
    __FN.fn._init.prototype = __FN.fn;
    return __FN.fn;
})();